package pl.dsp.dsp1.ui;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.EmptyBorder;

public class FilterWindow extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7875206368529457445L;

	private JSpinner mSpinner;
	private JSpinner fpSpinner;
	private JSpinner foSpinner;

	public FilterWindow(MainWindow owner, WindowController controller) {
		super(owner, "Filtering toolbox");
		controller.setFilterWindow(this);
		setResizable(false);
		setBounds(50, 50, 400, 150);

		JPanel contentPane = new JPanel(new BorderLayout(0,2));
		setContentPane(contentPane);
		contentPane.setBorder(new EmptyBorder(2, 2, 2, 2));

		JPanel actionMenu = new JPanel(new GridLayout(0, 2));
		contentPane.add(actionMenu, BorderLayout.CENTER);
		JButton lowpassButton = new JButton("Lowpass");
		lowpassButton.addActionListener(controller);
		actionMenu.add(lowpassButton);
		JButton bandpassButton = new JButton("Lowpass->Bandpass");
		bandpassButton.addActionListener(controller);
		actionMenu.add(bandpassButton);
		JButton blackmanButton = new JButton("Blackman");
		blackmanButton.addActionListener(controller);
		actionMenu.add(blackmanButton);
		
		JPanel settingMenu = new JPanel(new GridLayout(0,2));
		contentPane.add(settingMenu, BorderLayout.SOUTH);

		JLabel mLabel = new JLabel("M:");
		mSpinner = new JSpinner();
		mSpinner.setModel(new SpinnerNumberModel(new Integer(5), null, null,
				new Integer(1)));
		settingMenu.add(mLabel);
		settingMenu.add(mSpinner);

		JPanel fpPanel = new JPanel(new GridLayout(0,2));
		JLabel fpLabel = new JLabel("Fp:");
		fpSpinner = new JSpinner();
		fpSpinner.setModel(new SpinnerNumberModel(new Double(5), null, null,
				new Double(1)));
		
		fpPanel.add(fpSpinner);
		JButton inferButton = new JButton("Infer");
		inferButton.addActionListener(controller);
		fpPanel.add(inferButton);
		settingMenu.add(fpLabel);
		settingMenu.add(fpPanel);

		JLabel foLabel = new JLabel("Fo:");
		foSpinner = new JSpinner();
		foSpinner.setModel(new SpinnerNumberModel(new Double(5), null, null,
				new Double(1)));
		settingMenu.add(foLabel);
		settingMenu.add(foSpinner);
	}

	public double getFp() {
		return (Double) fpSpinner.getModel().getValue();
	}

	public void setFp(double fp) {
		this.fpSpinner.getModel().setValue(new Double(fp));
	}

	public int getM() {
		return (Integer) mSpinner.getModel().getValue();
	}

	public double getFo() {
		return (Double) foSpinner.getModel().getValue();
	}
}
